/*
 * Copyright 2007 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
import org.codehaus.groovy.grails.commons.ApplicationHolder
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
import org.codehaus.groovy.grails.plugins.GrailsPlugin
import org.springframework.web.context.request.RequestContextHolder
import org.codehaus.groovy.grails.plugins.PluginManagerHolder

/** 
 * Argh so much pain and diminishing returns, not testing this... leave til later
 * @author Marc Palmer (marc@anyware.co.uk)
 */
class RenderMethodTests extends GroovyTestCase {

    // @todo Find a way to do this properly, need a TargetSource etc
    Class addController(src) {
		def gcl = new GroovyClassLoader()
		def c = gcl.parseClass(src)
        return c
    }

	void testRenderNestedNodes() {
	    def c = addController("""
class TestController {
	def index = {
		def articles = ['A', 'B', 'C']

		render(feedType:"rss", feedVersion:"2.0") {
			title = 'Test feed'
			link = 'http://somewhere.com/'

			articles.each() { article ->
				entry("Title for \$article") {
					content(type:"text/plain") {
					    "Content for \$article"
                    }
                }
            }
        }
    }
}""")

        def controller = c.newInstance()
        //controller.index()
        
        //assertNotNull controller.render 
	}

	void testRenderNodes() {
        def c = addController("""
class TestController {
	def index = {
		def articles = ['A', 'B', 'C']

		render(feedType:"rss", feedVersion:"2.0") {
			title = 'Test feed'
			link = 'http://somewhere.com/'

			articles.each() { article ->
				entry("Title for \$article") {
				    "Content for \$article"
				}
			}
		}
	}
}
""")

        def controller = c.newInstance()
        //controller.index()

        //assertNotNull controller.render 
	}
}
